package hl.demosample.viewmodel.request

import androidx.lifecycle.MutableLiveData
import hl.demosample.app.network.apiService2
import hl.demosample.app.network.stateCallback.ListDataUiState
import hl.demosample.data.model.bean.WeekHotData
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request
import me.hgj.jetpackmvvm.state.ResultState

/*
* path: DemoSample 
* Author: 86133
* Create: 2021-06-30 12:34
* Changes (from 2021-06-30)
* Desc:
*/
class RequestWeekHotViewModel : BaseViewModel() {

    var mData = MutableLiveData<ListDataUiState<WeekHotData>>()

    fun weekHot(hot_type: String, category: String, count: Int) {
        request({ apiService2.weekHot(hot_type, category, count) }, {
            val dataUiState =
                ListDataUiState(
                    isSuccess = true,
                    listData = it
                )
            mData.value = dataUiState
        },{
            val dataUiState =  ListDataUiState(
                isSuccess = false,
                errMessage= it.message.toString(),
                listData = arrayListOf<WeekHotData>()
            )
            mData.value = dataUiState
        })
    }
}